package com.lottery.shadowbd.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lottery.shadowbd.R;
import com.lottery.shadowbd.bean.Rule;
import com.lottery.shadowbd.bean.TestNews;
import com.lottery.shadowbd.callback.OnMyItemClickListener;

import java.util.List;

/**
 * Created by Administrator on 2017/4/1 0001.
 */
public class LotRuleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<Rule> mList;

    private OnMyItemClickListener myItemClickListener;

    public LotRuleAdapter(Context mContext, List<Rule> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View mView = LayoutInflater.from(mContext).inflate(R.layout.item_rule, parent, false);

        ViewHolder holder = new ViewHolder(mView);

        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final ViewHolder mHolder = (ViewHolder) holder;

        mHolder.tv_lot_rule.setText(mList.get(position).getName());

        if (myItemClickListener != null) {
            mHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    myItemClickListener.onItemClick(v, position);
                }
            });
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return mList != null ? mList.size() : 0;
    }

    public void setMyItemClickListener(OnMyItemClickListener myItemClickListener) {
        this.myItemClickListener = myItemClickListener;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        //标题
        TextView tv_lot_rule;

        public ViewHolder(View itemView) {
            super(itemView);

            tv_lot_rule = (TextView) itemView.findViewById(R.id.tv_lot_rule);
        }
    }
}
